package org.acme.oauth2.restclient;

import org.acme.oauth2.client.TdfOauth2Client;
import org.eclipse.microprofile.rest.client.inject.RestClient;

import javax.inject.Inject;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.net.URL;

/**
 * @author LiJian
 * @date 2021/6/8 11:01
 */
public class RestClientResource {
    @Inject
    @RestClient
    RestClientService restClientService;
    @Inject
    @RestClient
    TdfOauth2Client tdfOauth2Client;
    @GET
    @Path("/rest/password")
    @Produces(MediaType.APPLICATION_JSON)
    public Response accessToken(){
        return restClientService.getToken("tdfuivue","tdfuivue","admin","123456","password");
    }
    @GET
    @Path("/rest/me")
    @Produces(MediaType.APPLICATION_JSON)
    public Response getUser(){
        return tdfOauth2Client.getUserMessage();
    }
    @GET
    @Path("/rest/token")
    @Produces(MediaType.APPLICATION_JSON)
    public Response getToken(){
        return tdfOauth2Client.getAccessToken("yMOlfT","authorization_code","http://localhost:9527/ssologin");
    }
//    @GET
//    @Path("/ssologin")
//    @Produces(MediaType.APPLICATION_JSON)
//    @Consumes(MediaType.APPLICATION_JSON)
//    public String getCode(@QueryParam("code") String code,
//                            @QueryParam("state") String state){
//         System.out.println(code);
//         return code;
//        if(code!=null) {
//            Response response=tdfOauth2Client.getAccessToken(code,"authorization_code","http://localhost:9527/ssologin");
//            if(response.getStatus()==200){
//                String accessToken = response.readEntity();
//            }
//        }else{
//
//        }
        //return tdfOauth2Client.getAccessToken("yMOlfT","authorization_code","http://localhost:9527/ssologin");
//    }
}
